import jieba
from collections import Counter
from wordcloud import WordCloud
import matplotlib.pyplot as plt
txt = open(r"西游记.txt", "r", encoding='utf-8').read()
words = jieba.lcut(txt)
words = [word for word in words if len(word) > 1]
word_freq = Counter(words)
wordcloud = WordCloud(font_path='simhei.ttf', background_color='white',
                      width=800, height=400).generate_from_frequencies(word_freq)
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
